<?php include PATH_TPL."/admin/tpl.header.phtml"?>
<div class="main-container inner">
    <div class="main-content">
        <div class="container-fluid">
            <div class="row">
                <div class="col-lg-12 bg">
                    <ol class="breadcrumb">
                        <li class="active">
                            <i class="fa  fa-fw fa-reorder"></i>添加课程系列
                        </li>
                    </ol>
                </div>
            </div>


        <div id="course-content" class="tab-content">
<!-- 课程基础信息内容页 -->
            <div id="course-basic" class="tab-pane fade in active">
                <div class="container-fluid col-md-7 col-sx-12">
                    <form action="/admin_courseseries/add" method="post" enctype="multipart/form-data">
                        <div class="form-group ">
                            <label for="title">系列课程名称</label>
                            <input type="text" placeholder="输入系列课程名称" id="title" class="form-control" name="title">
                        </div>
                        <div class="form-group">
                            <label for="img">系列课程缩略图</label>
                            <input type="file" id="file_input" name="img">
                        </div>

                </div>
                <div class="container-fluid col-md-5">
                    <div class="images text-center" id="img_view">
                    </div>
                </div>
            </div> <!-- raper-->

        </div>   <!-- course-content-->
    <div class="col-md-2 col-md-offset-5  ">
    <button class="btn form-control btn-primary demo_2" type="button" id="submit">保存</button>
    </div>
</form>
        </div>
        <div class="subviews">
            <div class="subviews-container"></div>
        </div>
    </div>

    <!-- end: PAGE -->
</div>
<!-- end: MAIN CONTAINER -->
<script type="text/javascript" src="/plugins/jquery-ui-1.11.4/jquery-ui.min.js"></script>
<script>
$(function(){
    //提交    
    var options={
        beforeSubmit : showRequest,    // 提交前的回调函数
        success : showResponse,    // 提交后的回调函数
        dataType : "json",    // html（默认）、xml、script、json接受服务器端返回的类型
        timeout : 3000    // 限制请求的时间，当请求大于3秒后，跳出请求
    }
    function showRequest(formData, jqForm, options){
        return true;
    }
    function showResponse(responseText,statusText){
        cg_alert_add(responseText,'/admin_courseseries','/admin_courseseries/add');
    }

    $('#submit').click(function() {
        $('form').ajaxSubmit(options);
        return false;

    });
});

//FileReader显示素略图
var result = document.getElementById("img_view");
var input = document.getElementById("file_input");
if(typeof FileReader==='undefined'){
    result.innerHTML = "抱歉，你的浏览器不支持 FileReader";
    input.setAttribute('disabled','disabled');
}else{
    input.addEventListener('change',readFile,false);
}
function readFile(){
    var file = this.files[0];
    if(!/image\/\w+/.test(file.type)){
        alert("文件必须为图片！");
        return false;
    }
    var reader = new FileReader();
    reader.readAsDataURL(file);
    reader.onload = function(e){
        result.innerHTML = '<img src="'+this.result+'" alt="" width="400px"/>'
    }
}
</script>
<?php include PATH_TPL."/admin/tpl.footer.phtml"?>
